/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package observer_cod_ruim;

import java.util.ArrayList;

/**
 *
 * @author Marcel
 */
public class WeatherData implements Subject {
    private ArrayList observers;
    private float temperature;
    private float pressure;
    private float humidity;
    
    public WeatherData () {
        observers = new ArrayList();
    }
    
    @Override
    public void registerObserver (Observer o) {
        observers.add(o);
    }
    
    @Override
    public void removeObserver (Observer o) {
        int i = observers.indexOf(o);
        if (i >= 0) {
            observers.remove(o);
        }
    }
    @Override
    public void notifyObserver () {
        for (int i = 0; i < observers.size(); i++) {
            Observer observer = (Observer) observers.get(i);
            observer.update(temperature, humidity, pressure);
        }
    }
    
    public void measurementsChanged () {
        notifyObserver();
    }
    
    public void setMeasurements (float temperatures, float humidity, float pressure) {
        this.temperature = temperatures;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }
}
